package com.cxrj.zhsq.userManage.controller;

import java.util.HashMap;
import java.util.Map;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import com.cxrj.zhsq.userManage.service.DirectoriesService;

/**
 * 
 * @author wangge
 * 
 */
@RestController
public class DirectoriesController {
	@Resource
	private DirectoriesService directoriesService;
	
	/**
	 * 分页查询不同部门对应的通讯录
	 * @param request
	 * @param response
	 * @return
	 */
	@RequestMapping("selectDirctories")
	public Map<String, Object> selectDirctories(HttpServletRequest request, HttpServletResponse response) {
		Map<String, Object> resultMap = directoriesService.selectDirectoriesPager(request,response);
		return resultMap;
	}
	
	/**
	 * 添加及修改通讯录信息
	 * @param organizationId
	 * @param name
	 * @param tel
	 * @param id
	 * @return
	 */
	@RequestMapping(value = "insertDirectories", method = RequestMethod.POST)
	public Map<String, Object> insertDirectories(String organizationId,String name,String tel,String id) {
		Map<String, Object> resultMap = new HashMap<>();
		try {
			directoriesService.insertDirectories(organizationId,name,tel,id);
			resultMap.put("result", 0);
		} catch (Exception e) {
			resultMap.put("result", -1);
			e.printStackTrace();
		}
		return resultMap;
	}
	
	/**
	 * 根据id查询
	 * @param id
	 * @return
	 */
	@RequestMapping("selectDirctoriesById")
	public Map<String, Object> selectDirctoriesById(String id) {
		Map<String, Object> resultMap = directoriesService.selectDirectoriesById(id);
		return resultMap;
	}
	
	/**
	 * 删除通讯录
	 * @param id
	 * @return
	 */
	@RequestMapping(value = "deleteDirectories", method = RequestMethod.POST)
	public Map<String, Object> deleteDirectories(String id) {
		Map<String, Object> resultMap = new HashMap<>();
		try {
			directoriesService.deleteDirectories(id);
			resultMap.put("result", 0);
		} catch (Exception e) {
			resultMap.put("result", -1);
			e.printStackTrace();
		}
		return resultMap;
	}
}
